window.onload = function () {
    var form = document.querySelector('form');
    var imgs = document.querySelectorAll('.img span img');
    var head = document.querySelector('#head');
    var nickname = document.querySelector('#nickname');
    var btn = document.querySelector('#btn');
    var login = document.querySelector('.login');

    for (let i = 0; i < imgs.length; i++) {
        imgs[i].index = i;
        imgs[i].onclick = function () {
            head.src = '../img/img' + (this.index + 2) + '.jpg';
        }
    }

    head.onclick = function () {
        head.src = '../img/img1.jpg';
    }


    var reg = /^[\u4e00-\u9fa5]{0,}$/;
    var span = document.querySelector('.judge');
    nickname.onblur = function () {
        if (!reg.test(nickname.value) && nickname.value !== '') {
            btn.style.display = 'none';
            span.style.display = 'inline-block';
            span.innerText = '请输入中文名字';
            nickname.value = '';
        } else {
            btn.style.display = 'block';

        }
    }
    nickname.onfocus = function () {
        span.style.display = 'none';
        btn.style.display = 'block';
    }

    var main = document.querySelector('.main');
    btn.onclick = obtain;
    function obtain() {
        if (nickname.value) {
            login.style.display = 'none';
            main.style.display = 'block';

        }
        var userName = nickname.value;
        return userName;
    }
    var userName = obtain();
    console.log(userName);
    var comment = document.querySelector('.comment');
    //获取用户昵称

    var callback = document.querySelector('.callback');
    callback.onclick = function () {
        window.location.href = 'index2.html';
    }

}